package fede.common.utils;

import java.util.Calendar;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class MyLoggerFormatter extends Formatter {

	@Override
	public String format(LogRecord record) {
		String s = "";
		
		s += "[" + daMillisADate(record.getMillis()) + "]\t";
		s += record.getSourceClassName() + "\t";
		s += record.getSourceMethodName() + "\t";
		s += record.getLevel() + ":\t";
		s += record.getMessage() + "\n";
		
		return s;
	}
	
	
	private String daMillisADate(long millis) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(millis);
		String s = "";
		
		s += cal.get(Calendar.YEAR);
		s += "-";
		s += (new String(""+cal.get(Calendar.MONTH)).length() < 2 ? "0" : "") + cal.get(Calendar.MONTH);
		s += "-";
		s += (new String(""+cal.get(Calendar.DAY_OF_MONTH)).length() < 2 ? "0" : "") + cal.get(Calendar.DAY_OF_MONTH);
		s += " ";
		s += (new String(""+cal.get(Calendar.HOUR_OF_DAY)).length() < 2 ? "0" : "") + cal.get(Calendar.HOUR_OF_DAY);
		s += ":";
		s += (new String(""+cal.get(Calendar.MINUTE)).length() < 2 ? "0" : "") + cal.get(Calendar.MINUTE);
		s += ":";
		s += (new String(""+cal.get(Calendar.SECOND)).length() < 2 ? "0" : "") + cal.get(Calendar.SECOND);
		s += ",";
		s += (new String(""+cal.get(Calendar.MILLISECOND)).length() == 1 ? "00" : "");
		s += (new String(""+cal.get(Calendar.MILLISECOND)).length() == 2 ? "0" : "");
		s += cal.get(Calendar.MILLISECOND);
		
		return s;
	}
}

